package registnet.records.summary.honorary.source;

import java.util.List;

import registnet.dao.CollegePeer;
import registnet.dao.StudentPeer;
import registnet.records.College;
import registnet.records.Curriculum;
import registnet.records.Form5;
import registnet.records.Student;
import registnet.records.source.DegreeProgramSource;
import registnet.records.source.Form5Source;
import registnet.records.summary.honorary.CollegeScholars;
import registnet.records.summary.honorary.IHonoraryStudents;

public class CollegeScholarsSource implements IHonoraryStudentsSource{

	private College college;
	private int year;
	private int semester;
	private CollegeScholars collegeScholars;
	
	public CollegeScholarsSource(int semester, int year){
		this.semester = semester;
		this.year = year;
		this.load();
	}
	
	public CollegeScholarsSource(College college, int semester, int year){
		this.college = college;
		this.semester = semester;
		this.year = year;
		this.load();
	}
	
	public void load(){
		StudentPeer sp = new StudentPeer();
		List<registnet.dao.Student> students;
		if (this.college == null){
			students = sp.getAllStudents();
			this.collegeScholars = new CollegeScholars(this.semester, this.year);
		}
		else{
			students = sp.getStudentByCollege(new CollegePeer().getCollegeId(this.college.getCollegeCode()));
			this.collegeScholars = new CollegeScholars(this.college, this.semester, this.year);
		}
		for(int i=0; i<students.size(); i++){
			try{
				registnet.dao.Student DAOStudent = students.get(i);
				Student student = new Student(DAOStudent.getStudentNumber());
				student.setFirstName(DAOStudent.getFirstName());
				student.setMiddleName(DAOStudent.getMiddleName());
				student.setLastName(DAOStudent.getLastName());
				student.setSex(DAOStudent.getSex());
				student.setCurriculum(new Curriculum(DAOStudent.getCurriculum().getCurriculumCode()));
				student.getCurriculum().setDegreeProgram(new DegreeProgramSource(DAOStudent.getCurriculum().getDegreeCourse().getDegreeCode()).getDegreeProgram());
				Form5 form5 = new Form5Source(student, this.semester, this.year).getForm5();
				double GWA = form5.getGWA();
				if(GWA <= 1.75 && GWA > 1.45)
					this.collegeScholars.add(student, GWA);
			}catch(Exception e){}
		}
		
	}
	
	public IHonoraryStudents getHonoraryStudents(){
		return this.collegeScholars;
	}
	
}
